package com.snopy.designPattern.create.singleton;

/**
 * @author snopy
 * @version 1.0.0
 * @classname SingletonD
 * @description
 * @email 77912204@qq.com
 * @date 2022/06/27 22:02
 */
public final class SingletonD {
    private SingletonD(){}
    //问题1：解释为什么要加volatile?
    /*
    *
    * */
    private static volatile SingletonD INSTANCE;
    //问题2：对比实现3,说出这样做的意义
    /*
    *
    * */
    public static SingletonD getInstance(){
        if (INSTANCE!=null){
            return INSTANCE;
        }
        synchronized (SingletonD.class){
            //问题3：为什么还要在这里加空判断，之前不是判断过了？
            if (INSTANCE!=null){
                return INSTANCE;
            }
            INSTANCE = new SingletonD();
            return INSTANCE;

        }
    }

}
